package com.example.yuntiku.Servlet;

import com.example.yuntiku.Service.HistoryService;
import com.example.yuntiku.Vo.History;
import com.example.yuntiku.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "HistoryServlet", value = "/HistoryServlet")
public class HistoryServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        System.out.println("HistoryServlet我的历史——---");
        HistoryService historyService = new HistoryService();
        User user = (User) request.getSession().getAttribute("user");
        //获取用户Id
        int i  = user.getUid();
        //获取是自测还是考试
        String type=request.getParameter("type");
        if(type==null){
            type = "2";
        }
        List<History> list = historyService.selectHistory(i, Integer.parseInt(type));
        request.setAttribute("shutls",list);
        request.setAttribute("type",type);
        request.getRequestDispatcher("history.jsp").forward(request,response);
    }
}